package Controller.Actions;

import Controller.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import Model.Beans.Results.*;
import Model.Beans.*;
import Model.QBE.*;

public class ValidateAction implements Action {

    private String name;
    
    public ValidateAction() 
    {
        this.name = "Validate";
    }    
    
    public String getName()
    {
        return name;
    }
   
    public void perform(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        StudentModel smodel = new StudentModel();
        String id = request.getParameter("id");
        
        
        PersonList list = smodel.search(new Person());
        
        ArrayList array = list.getPersons();
        
        for(int i=0; i<array.size(); i++)
        {
            Person tmp = (Person)array.get(i);
            if(tmp.getId() == Integer.parseInt(id))
            {
                response.setContentType("text/xml");
                response.setHeader("Cache-Control", "no-cache");
                response.getWriter().write("<valid>true</valid>");
                return;
            }
        }    
        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        response.getWriter().write("<valid>false</valid>");
    }
}
